from flask import Blueprint, request
from libs.readcsv import health_fetchRow,health_forecast
import json
from flask_cors import CORS
import pandas as pd
from datetime import datetime
# from libs.forcastdata import predictmodel


health_bp = Blueprint("healthapi", __name__)
cors = CORS(health_bp)


@health_bp.route('/fetchRowHealth', methods=['GET'])
def getfetchRow():
    json_list = []
    bucketName = request.args.get('bucktName')
    data = health_fetchRow(bucketName)

    for index, row in data.iterrows():
        json_obj = {
            "Date": row['date'],
            "scales": row['value']
        }
        json_list.append(json_obj)

    return json.dumps(json_list)


@health_bp.route('/forecastHealth', methods=['GET'])
def getforcastdata():
    json_list = []
    bucketName = request.args.get('bucktName')
    data = health_forecast(bucketName)

    for index, row in data.iterrows():
        json_obj = {
            "Date": row['date'],
            "scales": row['value']
        }
        json_list.append(json_obj)

    return json.dumps(json_list)